﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FOModels.PHighLight;
using System.Data;
namespace DataAccess.PHighLight
{
    public class PHighLightDAL
    {
        SQLDataAccess db;
        public PHighLightDAL()
        {
            db = new SQLDataAccess();
        }

        public DataTable getTop5(int langid)
        {
            return db.exeSelect("select top 5 * from PHighLight p join PHighLightLang pl on p.PHighLightID = pl.PHighLightID where LangID = " + langid + " and Display = 1");
        }

        public DataTable gettop1()
        {
            return db.exeSelect("select top 1 * from PHighLight order by PHighLightID desc");
        }
        public DataTable getall(int langid)
        {
            return db.exeSelect("Select * from PHighLight p join PHighLightLang pl on p.PHighLightID = pl.PHighLightID join Language la on pl.LangID = la.ID where LangID =" + langid + "");
        }
        public DataTable getbyid(int PHighLightID, int langid)
        {
            return db.exeSelect("Select * from PHighLight p join PHighLightLang pl on p.PHighLightID = pl.PHighLightID where LangID =" + langid + "  and pl.PHighLightID = " + PHighLightID + "");
        }
        public int UpdatePHighLight(PHighLightModels models)
        {
            return db.exeUpdate("update PHighLight set PHighLightName = N'" + models.PHighLightName + "',Display='" + models.Display + "',OrderSort=" + models.OrderSort + ",Link='" + models.Link + "' where PHighLightID = " + models.PHighLightID + "");
        }
        public int UpdatePHighLightLang(PHighLightModels models, int langid)
        {
            return db.exeUpdate("update PHighLightLang set PHighLightName = N'" + models.PHighLightName + "',PHighLightContent = N'" + models.PHighLightContent + "' where PHighLightID = " + models.PHighLightID + " and LangID = " + langid + "");
        }
        public int InsertPHighLight(PHighLightModels models)
        {
            return db.exeUpdate("insert into PHighLight(PHighLightName,Display,OrderSort,Link) values (N'" + models.PHighLightName + "','" + models.Display + "'," + models.OrderSort + ",'" + models.Link + "')");
        }
        public int InsertPHighLightLang(PHighLightModels models, int langid)
        {
            return db.exeUpdate("insert into PHighLightLang values (" + models.PHighLightID + "," + langid + ",N'" + models.PHighLightName + "',N'" + models.PHighLightContent + "')");
        }
        public int DeletePHighLight(int PHighLightID)
        {
            return db.exeUpdate("Delete from PHighLight where PHighLightID = " + PHighLightID + "");
        }
        public int DeletePHighLightLang(int PHighLightID)
        {
            return db.exeUpdate("Delete from PHighLightLang where PHighLightID = " + PHighLightID + "");
        }
    }
}
